package com.jy.framework.base.utils;

import java.math.BigDecimal;

public class Converter {

    public static String toString(Object obj) {
        return obj == null ? "" : obj.toString();
    }

    public static String toString(Object obj, String dftVal) {
        return obj == null ? dftVal : obj.toString();
    }

    /**
     * toDateStr
     */
    public static String toDateStr(java.util.Date date) {
        return DateUtil.getYYMMDD(date);
    }

    /**
     * toDate
     */
    public static java.util.Date toDate(String strDate) {
        return DateUtil.parse(strDate, "yyyyMMdd");
    }

    public static int toInt(Object obj) {
        if (obj instanceof BigDecimal){
            return ((BigDecimal) obj).intValue();
        }else if (obj instanceof String){
            return Integer.parseInt(obj.toString());
        }
        return 0;
    }
}
